package ltd.dujiabao.activemq.spring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

/**
 * @author : DuJiabao
 * @Project : active-mq
 * @Time : 2021/5/6 10:53
 * @Desc :
 */
@Service
public class ActiveMQConsumer {
  @Autowired
  JmsTemplate jmsTemplate;

  public String recieveText() {
    Object o = jmsTemplate.receiveAndConvert();
    if (o instanceof String) {
      String text = (String) o;
      System.out.println("收到消息： " + text);
      return text;
    } else return null;
  }
}
